***
* COSPONSORSHIP ANALYSIS
***
* Since the data manipulation is so computing intensive, this section starts with the .dta file generated by a setup file and then performs our analysis.
clear
use housebills_cospderiv.dta

rename type billtype
sort congress billnumber billtype
merge congress billnumber billtype using CongBillsProject_Slim.dta, _merge(bridge_merge)

sort congress billnumber billtype
order congress billnumber billtype bridge_merge
* these are bills with no cosponsors
drop if bridge_merge==2


* This generates a dummy variable for whether or not the bill ever went through the foreign affairs committee
gen foreignaffairs=0
forvalues i=1(1)5 {
replace foreignaffairs=1 if committee`i'=="House Foreign Affairs"
}

* This generates a dummy variable that equals one for bills and amendments (and zero for everything else)
gen billamend=0
replace billamend=1 if (billtype=="HR" | billtype=="HZ")
** This generates a dummy variable that equals one for bills only (excluding amendments)
** This is for the response to KT's response, where we say "Results obtain even when excluding amendments"
gen bill_noamend=0
replace bill_noamend=1 if (billtype=="HR")



*** This generates the Congress level variables WITHOUT billamend distinctions
bysort congress: egen cong_uw_all=mean(bill_sum01_abs)

bysort congress: egen cong_uw_foreignxx=mean(bill_sum01_abs) if foreign==1
bysort congress: egen cong_uw_foreign=min(cong_uw_foreignxx)

bysort congress: egen cong_uw_foreignaffxx=mean(bill_sum01_abs) if foreignaffairs==1
bysort congress: egen cong_uw_foreignaff=min(cong_uw_foreignaffxx)
drop *xx*


*** This generates the Congress level variables WITH billamend distinctions
bysort congress: egen cong_uw_all_baxx=mean(bill_sum01_abs) if billamend==1
bysort congress: egen cong_uw_all_ba=min(cong_uw_all_baxx)

bysort congress: egen cong_uw_foreign_baxx=mean(bill_sum01_abs) if foreign==1 & billamend==1
bysort congress: egen cong_uw_foreign_ba=min(cong_uw_foreign_baxx)

bysort congress: egen cong_uw_foreignaff_baxx=mean(bill_sum01_abs) if foreignaffairs==1 & billamend==1
bysort congress: egen cong_uw_foreignaff_ba=min(cong_uw_foreignaff_baxx)
drop *xx*

*** This generates the Congress level variables WITH bill_NOamend distinctions
* New for KT response response
bysort congress: egen cong_uw_all_bnaxx=mean(bill_sum01_abs) if bill_noamend==1
bysort congress: egen cong_uw_all_bna=min(cong_uw_all_bnaxx)

bysort congress: egen cong_uw_foreign_bnaxx=mean(bill_sum01_abs) if foreign==1 & bill_noamend==1
bysort congress: egen cong_uw_foreign_bna=min(cong_uw_foreign_bnaxx)

bysort congress: egen cong_uw_foreignaff_bnaxx=mean(bill_sum01_abs) if foreignaffairs==1 & bill_noamend==1
bysort congress: egen cong_uw_foreignaff_bna=min(cong_uw_foreignaff_bnaxx)
drop *xx*


* This codes bills by foreign vs domestic according to the policy agendas topic codes
gen foreignissue=.
replace foreignissue=1 if major==18 | major==19 | major==16
replace foreignissue=0 if foreignissue!=1 & major!=.
bysort congress: egen congiss_uw_allxx=mean(bill_sum01_abs) if foreignissue!=.
bysort congress: egen congiss_uw_all=min(congiss_uw_allxx)

bysort congress: egen congiss_uw_foreignxx=mean(bill_sum01_abs) if foreignissue==1
bysort congress: egen congiss_uw_foreign=min(congiss_uw_foreignxx)

drop *xx
saveold housebills_cospderiv2.dta, replace

duplicates drop congress, force
saveold housebills_cospderiv3.dta, replace


***
* Draft Figure 6
***
* This is the command for the cosponsorship plot in the draft.
twoway connected congiss_uw_all congiss_uw_foreign congress, xline(101) ylabel(0(.2)1, format(%02.1f)) title("Figure 6. Cosponsorship Balance, 1973-2003", size(medium)) yaxis(1) lp(dash solid) lw(medium medium) legend(order(1 "all bills" 2 "foreign policy bills")) xlabel(93(1)107) ytitle("cosponsorship balance") xtitle("Congress") msize(vsmall vsmall)
* This is for the KT response, the plots for the lines excluding amendments and resolutions look the same.
twoway connected congiss_uw_all congiss_uw_foreign cong_uw_all_bna cong_uw_foreign_bna congress, xline(101) ylabel(0(.2)1, format(%02.1f)) title("Figure 6. Cosponsorship Balance, 1973-2003", size(medium)) yaxis(1) xlabel(93(1)107) ytitle("cosponsorship balance") xtitle("Congress")

***
* Cold War Break Regressions
***
* These regressions give the coefficients and SE's mentioned in the footnote.
* For the regressions, this reloads the dataset with bill observations, rather than congress observations.
use housebills_cospderiv2.dta, clear
*drop CWar*
forvalues i=100(1)103 {
est clear
gen CWar`i'=0
replace CWar`i'=1 if congress>=`i'
*reg bill_sum01_abs CWar`i' if foreign==1, cluster(congress)
*est store uw_for
reg bill_sum01_abs CWar`i' if foreignissue==1, cluster(congress)
*est store uw_foriss
* This was added for the KT response.  Nothing changes if you run these regressions only on bills (no amendments or resolutions).
reg bill_sum01_abs CWar`i' if foreignissue==1 & bill_noamend==1, cluster(congress)
*esta _all using "cosp_CWar`i'.doc", drop(_cons) title("Title") starlevels(+ 0.10 * 0.05 ** 0.01)  se  nom nonum nodep nogaps  b(a3)  label brackets  compress replace
}

***
* Regressions for cosponsorship balance over time
***
reg bill_sum01_abs congress if foreignissue==1, cluster(congress)
reg bill_sum01_abs congress, cluster(congress)
